package com.appistry.maven.plugin.far;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Assembles the dependencies required by the CloudIQ application
 * 
 * @goal assemble-dependencies
 * @phase package
 * @requiresDependencyResolution runtime
 */
public class AssembleDependenciesMojo extends AbstractFarMojo {

	public void execute() throws MojoExecutionException, MojoFailureException {
		// if src/main/fabric-resources (or specified) directory does not exist,
		// then throw return
		// This check is not really required for this mojo since we are not
		// copying anything from this folder. But having this check helps since
		// Maven includes this goal in the default lifecycle which could
		// unnecessarily cause this goal to be run for modules that are not
		// meant to be "fabric/far packaged"
		if (!existsFabricResourcesSourceDirectory()) {
			return;
		}

		getLog().debug("In AssembleDependenciesMojo");

		copyPrimaryArtifact();
		assembleDependencies();
	}

	private void assembleDependencies() throws MojoExecutionException {
		getLog().debug("Assembling depedencies");

		assembleFabricDependencies(getFabricAppLibsDirectory());
	}

}
